package com.ronghuanet.basic.service.impl;

import com.ronghuanet.basic.service.IFastDfsService;
import com.ronghuanet.basic.util.FastdfsUtil;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

@Service
public class FastDfsServiceImpl implements IFastDfsService {

    @Value("${fastdfs.url}")
    private String fastDfsUrl;

    @Override
    public String upload(byte[] bytes, String extName) {
        return fastDfsUrl+FastdfsUtil.upload(bytes,extName);
    }

    @Override
    public void delete(String path) {
        //传入的path是有http://ip:port
        //但是我们的工具类不要
        //http://115.159.217.249:8888/group1/M00/00/00/rBEAA2MVmliAWdWWAACLuUIEKsg899.jpg
        path = path.substring(fastDfsUrl.length()); //     /group1/M00/00/00/rBEAA2MVmliAWdWWAACLuUIEKsg899.jpg
        FastdfsUtil.delete(path);
    }

    public static void main(String[] args) {
        String path = "http://115.159.217.249:8888/group1/M00/00/00/rBEAA2MVmliAWdWWAACLuUIEKsg899.jpg";
        System.out.println(path.substring("http://115.159.217.249:8888".length()));
    }
}
